const Mock = require('mockjs')
const Random = Mock.Random
const getQuestionList = require('./data/getQuestionList')

module.exports = [
  {
    // 获取单个问卷信息
    url: '/api/question/:id',
    method: 'get',
    response: () => {
      return {
        code: 200,
        data: {
          name: Random.cname(),
          age: Random.natural(0, 100),
          id: Random.id(10000, 99999)
        }
      }
    }
  },
  {
    // 创建问卷
    url: '/api/question',
    method: 'post',
    response: () => {
      return {
        code: 200,
        data: {
          id: Random.id()
        }
      }
    }
  },
  {
    // 获取问卷列表
    url: '/api/question',
    method: 'get',
    response (ctx) {
      const { url, query } = ctx
      const isStar = url.indexOf('isStar') >= 0
      const isDeleted = url.indexOf('isDeleted') >= 0
      const pageSize = parseInt(query.pageSize) || 10

      return {
        code: 200,
        data: {
          list: getQuestionList({ len: pageSize, isStar, isDeleted }), // 当前页
          total: 100 // 分页总数
        }
      }
    }
  },
  {
    // 更新问卷
    url: '/api/question/:id',
    method: 'patch',
    response: () => {
      return {
        code: 200
      }
    }
  },
  {
    // 复制问卷
    url: '/api/question/copy/:id',
    method: 'post',
    response: () => {
      return {
        code: 200,
        data: {
          id: Random.id()
        }
      }
    }
  },
  {
    // 批量彻底删除
    url: '/api/question',
    method: 'delete',
    response: () => {
      return {
        code: 200
      }
    }
  }
]
